﻿using Lhz.Sc.Entity.Database;
using Lhz.Sc.Entity.Enum;
using System;
using System.Collections.Generic;

namespace Lhz.Sc.Test
{
    public static class TestEntityBuilder
    {
        public static User BuildUser()
        {
            return new User()
            {
                Username = "AtUsername" + Guid.NewGuid(),
                Password = "AtPassword",
                IsAdmin = false,
                Name = "AtName",
                Phone = "13888888888"
            };
        }

        public static Application BuildApplication()
        {
            return new Application()
            {
                No = "AtNo" + Guid.NewGuid(),
                Name = "AtName" + Guid.NewGuid(),
                Description = "AtDescription"
            };
        }

        public static Log BuildLog(User user)
        {
            var dtNow = DateTime.Now;
            dtNow = DateTime.Parse(dtNow.ToString("yyyy-MM-dd hh:mm:ss"));
            return new Log()
            {
                Ip = "192.168.1.1",
                UserGuid = user.Guid,
                User = user,
                InvokeDatetime = dtNow,
                CompleteDatetime = dtNow.AddSeconds(1),
                InvokeResult = "AtInvokeResult",
                IsSuccess = true
            };
        }

        public static Service BuildService(Application application)
        {
            return new Service()
            {
                ApplicationGuid = application.Guid,
                Application = application,
                No = "AtNo" + Guid.NewGuid(),
                Name = "AtName",
                Url = "AtUrl",
                Description = "AtDescription",
                Operations = new List<Operation>()
            };
        }

        public static Operation BuildOperation(Service service)
        {
            return new Operation()
            {
                ServiceGuid = service.Guid,
                Service = service,
                No = "AtNo" + Guid.NewGuid(),
                Name = "AtName",
                Description = "AtDescription"
            };
        }

        public static Authorization BuildAuthorization(User user)
        {
            return new Authorization()
            {
                UserGuid = user.Guid,
                User = user,
                ObjectGuid = Guid.NewGuid(),
                AuthorizationType = AuthorizationType.ApplicationAuthorization
            };
        }
    }
}
